package com.ruoyi.business.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.business.domain.BusYjhzCropArea;
import com.ruoyi.business.service.IBusYjhzCropAreaService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 作物种植面积Controller
 * 
 * @author ruoyi
 * @date 2023-07-30
 */
@RestController
@RequestMapping("/yjhz/crop_area")
@Api(tags = "有机旱作-种植面积")
public class BusYjhzCropAreaController extends BaseController
{
    @Autowired
    private IBusYjhzCropAreaService busYjhzCropAreaService;

    /**
     * 查询作物种植面积列表
     */
    @GetMapping("/list")
    @ApiOperation("列表 ")
    public TableDataInfo list(BusYjhzCropArea busYjhzCropArea)
    {
        startPage();
        List<BusYjhzCropArea> list = busYjhzCropAreaService.selectBusYjhzCropAreaList(busYjhzCropArea);
        return getDataTable(list);
    }

    /**
     * 导出作物种植面积列表
     */
    @PreAuthorize("@ss.hasPermi('yjhz:crop_area:export')")
    @Log(title = "作物种植面积", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BusYjhzCropArea busYjhzCropArea)
    {
        List<BusYjhzCropArea> list = busYjhzCropAreaService.selectBusYjhzCropAreaList(busYjhzCropArea);
        ExcelUtil<BusYjhzCropArea> util = new ExcelUtil<BusYjhzCropArea>(BusYjhzCropArea.class);
        util.exportExcel(response, list, "作物种植面积数据");
    }

    /**
     * 获取作物种植面积详细信息
     */
    @PreAuthorize("@ss.hasPermi('yjhz:crop_area:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(busYjhzCropAreaService.selectBusYjhzCropAreaById(id));
    }

    /**
     * 新增作物种植面积
     */
    @PreAuthorize("@ss.hasPermi('yjhz:crop_area:add')")
    @Log(title = "作物种植面积", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BusYjhzCropArea busYjhzCropArea)
    {
        return toAjax(busYjhzCropAreaService.insertBusYjhzCropArea(busYjhzCropArea));
    }

    /**
     * 修改作物种植面积
     */
    @PreAuthorize("@ss.hasPermi('yjhz:crop_area:edit')")
    @Log(title = "作物种植面积", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BusYjhzCropArea busYjhzCropArea)
    {
        return toAjax(busYjhzCropAreaService.updateBusYjhzCropArea(busYjhzCropArea));
    }

    /**
     * 删除作物种植面积
     */
    @PreAuthorize("@ss.hasPermi('yjhz:crop_area:remove')")
    @Log(title = "作物种植面积", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(busYjhzCropAreaService.deleteBusYjhzCropAreaByIds(ids));
    }
}
